﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnionPay4WP
{

    /// <summary>
    /// 模拟指针的类
    /// </summary>
    public class Point<T> 
    {
        private int position = 0;


        /// <summary>
        /// 当前指向位置
        /// </summary>
        public int Position
        {
            get { return position; }
            set
            { 
                position = value;
            }
        }
        private T[] array = null;

        public T[] Array { get { return array; } }

        public Point(T[] arr, int postion = 0)
        {
            this.array = arr;
            Position = position;
        }

        public Point(T[] arr)
        {
            this.array = arr;
        }
        public Point(Point<T> p)
        {
            this.array = p.array;
            this.Position = p.Position;
        }
       

        public T this[int index]
        {
            get
            {
                if (index < 0 || index >= array.Length)
                    throw new IndexOutOfRangeException();
                return this.array[index];
            }
            set
            {
                if (index < 0 || index >= array.Length)
                    throw new IndexOutOfRangeException();
                  this.array[index] = value;
            }
             
        }

        public T Now
        {
            get { return array[Position]; }
            set
            {
                array[Position] = value;
            }
        }
        public int Length { get { return this.array.Length; } }

        public static Point<T> operator ++(Point<T> t)
        {
            Point<T> ret = t.Clone();
            ret.Position++;
            return ret;
        }
        public static Point<T> operator --(Point<T> t)
        {
            Point<T> ret = t.Clone();
            ret.Position--;
            return ret;
        }
       


        //public object Clone()
        //{
        //    return new Point<T>(this);
        //}
        public Point<T> Clone()
        {
            return new Point<T>(this);
        } 
    }

 
}
